<div class="panel panel-default">
    <div class="panel-heading case-detail-title">
        <ul class="nav nav-line-tab">
            <li class="active">联系人</li>
        </ul>
    </div>
    <div class="tab-content">
        <div class="td-check-panel tab-pane fade in active" id="casedetail-tel">
            <div class="panel-body panel-body-up-table">
                <div class="up-table">
                    <div class="action">
                                    <span class="pull-right">
                                        <if condition="fa_has_auth($custom['leader_user_id'])">
                                            <a role="button" data-toggle="modal" data-target="#edit-custom-contact" class="btn btn-link margin-left-10">新增电话</a>
                                        <else/>
                                            <a disabled="disabled" role="button" data-toggle="modal" data-target="#edit-custom-contact"
                                               class="btn btn-link margin-left-10">新增电话</a>
                                        </if>
                                    </span>

                        <span class="btn-group selected-action">
                                        <span class="btn btn-label disabled action-label">已选中 <strong class="selected-case">0</strong> 个电话</span>
                                        <a href="#" data-toggle="modal" data-target="#list-follow" class="btn btn-operate-link disabled"
                                           data-type="follow-list">通话记录</a>
                                    </span>
                    </div>
                </div>
            </div>
            <div class="">
                <input class="checked-item" type="hidden">
                <table class="table-check table-link-hover table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th class="td-check"><i class="check-all fa fa-square-o"></i></th>
                        <th style="width:80px;">姓名</th>
                        <th style="width:80px;">职位</th>
                        <!--<th>类型</th>-->
                        <th style="width:100px;">手机</th>
                        <th style="width:100px;">固话</th>
                        <th>备注</th>
                        <th style="width:80px;">来源</th>
                        <th style="width:80px;">跟进次数</th>
                        <th style="width:80px;"></th>
                    </tr>
                    </thead>
                    <tbody id="info-tbody">
                    <volist name="custom['custom_contacts']" id="contact">
                        <tr data-valueid="{$contact.id}"
                            data-name="{$contact.name}"
                            data-job="{$contact.job}"
                            data-type_name="{$contact.type_name}"
                            data-phone="{$contact.phone}"
                            data-tel="{$contact.tel}"
                            data-remark="{$contact.remark}"
                            data-source="{$contact.source}"
                        >
                            <td class="td-check">
                                <i class="check-item fa fa-square-o"></i>
                            </td>
                            <td>{$contact.name}</td>
                            <td>{$contact.job}</td>
                            <!--<td>{$contact.type_name}</td>-->
                            <td>
                                <span class="dropdown">
                                    <a role="button" data-type="edit-follow" data-toggle="dropdown">{$contact.phone}</a>
                                    <ul class="dropdown-menu dropdown-menu-side">
                                         <volist name="numbers" id="number">
                                            <li>
                                                <a role="button" class="callmobile" data-type="dialing-link"
                                                   data-number="{$number.number}"
                                                   data-ip="{$number.ip}"><i class="fa fa-mobile">  </i><span>{$number.number}</span></a>
                                            </li>
                                         </volist>
                                    </ul>
                                </span>
                            </td>
                            <td>
                                <span class="dropdown">
                                    <a role="button" data-type="edit-follow" data-toggle="dropdown">{$contact.tel}</a>
                                    <ul class="dropdown-menu dropdown-menu-side">
                                        <volist name="numbers" id="number">
                                            <li>
                                                <a role="button" class="callmobile" data-type="dialing-link"
                                                   data-number="{$number.number}"
                                                   data-ip="{$number.ip}"><i class="fa fa-mobile">  </i><span>{$number.number}</span></a>
                                            </li>
                                         </volist>
                                    </ul>
                                </span>
                            </td>
                            <td>{$contact.remark}</td>
                            <td>
                                {$contact.source|fc_config_name_by_key="Custom_Source",###}
                            </td>
                            <td><a href="#" data-toggle="modal" data-target="#list-follow" data-type="follow-list-a">{$contact.follow_times}</a></td>
                            <td class="td-action">
                                <a data-toggle="modal" data-target="#edit-custom-contact" class="btn btn-link btn-xs"><i class="fa fa-pencil"></i></a>
                                <a data-type="delete-custom-contact" class="btn btn-link btn-xs"><i class="fa fa-trash-o"></i></a>
                            </td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('a[data-type="follow-list-a"]').click(function () {
            var $tr = $(this).parent().parent();
            var phones = $tr.data('phone');
            get_follow(phones);
        });

        $('a[data-type="follow-list"]').click(function () {
            var phones = "";
            var tel = "";
            var checks = $("#info-tbody").find(".check-item-checked");
            checks.each(function () {
                phones += phones === "" ? $(this).parent().parent().data('phone') : "," + $(this).parent().parent().data('phone');
                tel += tel === "" ? $(this).parent().parent().data('tel') : "," + $(this).parent().parent().data('tel');
            });

            var list = "";
            if (phones === "" || tel === "") {
                list = phones + tel;
            } else {
                list = phones + ',' + tel;
            }
            get_follow(list);
        });

        $('a[data-type="dialing-link"]').click(function () {
            var $this = $(this);
            var tel = $this.parent().parent().prev().text();
            var url = 'http://192.168.0.30:8000/search/phones/call_mobile?useraccount=' + $this.data('number') + '&mobile=' + tel + '&ip=' + $this.data('ip');
//            alert(url);
            $.get(url);
        });
    });

    function get_follow(phones) {
        var followtbody = $('#list-follow-tbody');
        followtbody.children().remove();
        var tr_temp = $('<tr></tr>');
        var td_temp = $('<td></td>');
        $.getJSON("/custom/index/activityListByPhone", {phones: phones, custom_id: $("#custom_id").val()},
            function (json) {
                $.each(json, function (index, row) {
                    var tr = tr_temp.clone();
                    tr.append(td_temp.clone().text(row['activity_time']));
                    tr.append(td_temp.clone().text(row['objective']));
                    tr.append(td_temp.clone().text(row['job']));
                    tr.append(td_temp.clone().text(row['phone']));
                    tr.append(td_temp.clone().text(row['tel']));
                    tr.append(td_temp.clone().text(row['info']));
                    tr.append(td_temp.clone().text(row['add_user_name']));

                    followtbody.append(tr);
                })
            });
    }
</script>

<include file="Index/Public/editcontact"/>
<include file="Index/Public/listfollow"/>

